package adpater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.a513.R;

import java.util.List;

import entity.BillInfo;

public class BillListAdapter extends BaseAdapter {
    private List<BillInfo> list;
    private Context context;

    public BillListAdapter(List<BillInfo> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VIewHolder holder = new VIewHolder();
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_data,null);
            holder.tv_date = convertView.findViewById(R.id.tv_da);
            holder.tv_desc = convertView.findViewById(R.id.tv_de);
            holder.tv_move = convertView.findViewById(R.id.tv_move);
            convertView.setTag(holder);

        }else{
            holder = (VIewHolder)convertView.getTag();
        }
        BillInfo info = list.get(position);
        holder.tv_date .setText(info.getDate());
        holder.tv_desc.setText(info.remark);
        holder.tv_move.setText(String.format("%s%d元",info.type == 0?"+":"-",(int) info.amount));
        return convertView;
    }
    public final class VIewHolder{
        public TextView tv_date;
        public TextView tv_move;
        public TextView tv_desc;
    }
}
